<?xml version="1.0"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html><head><title>SASAPI</title><script src="../../../quicknav.js" type="text/javascript"></script><script><!--
document.quicknavBasePath="../../../index-files";
//--></script><link href="../../../style.css" title="JavaDoc" rel="stylesheet" type="text/css"/><link href="../../../unnatural.css" title="Unnatural" rel="alternate stylesheet" type="text/css"/><link href="../../../overview-summary.html" title="Overview" rel="top"/><meta name="generator" content="http://www.badgers-in-foil.co.uk/projects/as2api/"/></head><body><pre><span class="lineno" id="1">     1  </span>
<span class="lineno" id="2">     2  </span><span class="comment doc">/**
<span class="lineno" id="3">     3  </span> * com.sekati.utils.StringUtils
<span class="lineno" id="4">     4  </span> * @version 1.3.1
<span class="lineno" id="5">     5  </span> * @author jason m horwitz | sekati.com
<span class="lineno" id="6">     6  </span> * Copyright (C) 2007  jason m horwitz, Sekat LLC. All Rights Reserved.
<span class="lineno" id="7">     7  </span> * Released under the MIT License: http://www.opensource.org/licenses/mit-license.php
<span class="lineno" id="8">     8  </span> */</span>
<span class="lineno" id="9">     9  </span> 
<span class="lineno" id="10">    10  </span><span class="comment doc">/**
<span class="lineno" id="11">    11  </span> * Static class wrapping various String utilities.
<span class="lineno" id="12">    12  </span> */</span>
<span class="lineno" id="13">    13  </span><span class="key">class</span> com.sekati.utils.StringUtils {
<span class="lineno" id="14">    14  </span>
<span class="lineno" id="15">    15  </span>	<span class="comment doc">/**
<span class="lineno" id="16">    16  </span>	 * search for key in string
<span class="lineno" id="17">    17  </span>	 * @param str (String)
<span class="lineno" id="18">    18  </span>	 * @param key (String)
<span class="lineno" id="19">    19  </span>	 * @return Boolean
<span class="lineno" id="20">    20  </span>	 */</span>
<span class="lineno" id="21">    21  </span>	<span class="key">public</span> <span class="key">static</span> <span class="key">function</span> search(str:String, key:String):Boolean {
<span class="lineno" id="22">    22  </span>		<span class="key">return</span> (str.indexOf( key ) &lt;= -<span class="num_const">1</span>) ? <span class="key">false</span> : <span class="key">true</span>;
<span class="lineno" id="23">    23  </span>	}
<span class="lineno" id="24">    24  </span>
<span class="lineno" id="25">    25  </span>	<span class="comment doc">/**
<span class="lineno" id="26">    26  </span>	 * search for key in string - case insensitive.
<span class="lineno" id="27">    27  </span>	 * @param str (String)
<span class="lineno" id="28">    28  </span>	 * @param key (String)
<span class="lineno" id="29">    29  </span>	 * @return Boolean
<span class="lineno" id="30">    30  </span>	 */</span>	
<span class="lineno" id="31">    31  </span>	<span class="key">public</span> <span class="key">static</span> <span class="key">function</span> searchCaseInsensitive(str:String, key:String):Boolean {
<span class="lineno" id="32">    32  </span>		<span class="key">return</span> StringUtils.search( str.toUpperCase( ), key.toUpperCase( ) );
<span class="lineno" id="33">    33  </span>	}	
<span class="lineno" id="34">    34  </span>
<span class="lineno" id="35">    35  </span>	<span class="comment doc">/**
<span class="lineno" id="36">    36  </span>	 * replace every instance of a string with something else
<span class="lineno" id="37">    37  </span>	 * @param str (String)
<span class="lineno" id="38">    38  </span>	 * @param oldChar (String)
<span class="lineno" id="39">    39  </span>	 * @param newChar (String)
<span class="lineno" id="40">    40  </span>	 * @return String
<span class="lineno" id="41">    41  </span>	 */</span>
<span class="lineno" id="42">    42  </span>	<span class="key">public</span> <span class="key">static</span> <span class="key">function</span> replace(str:String, oldChar:String, newChar:String):String {
<span class="lineno" id="43">    43  </span>		<span class="key">return</span> str.split( oldChar ).join( newChar );
<span class="lineno" id="44">    44  </span>	}
<span class="lineno" id="45">    45  </span>
<span class="lineno" id="46">    46  </span>	<span class="comment doc">/**
<span class="lineno" id="47">    47  </span>	 * remove spaces
<span class="lineno" id="48">    48  </span>	 * @param str (String)
<span class="lineno" id="49">    49  </span>	 * @return String
<span class="lineno" id="50">    50  </span>	 */</span>
<span class="lineno" id="51">    51  </span>	<span class="key">public</span> <span class="key">static</span> <span class="key">function</span> removeSpaces(str:String):String {
<span class="lineno" id="52">    52  </span>		<span class="key">return</span> replace( str, <span class="str_const">" "</span>, <span class="str_const">""</span> );
<span class="lineno" id="53">    53  </span>	}
<span class="lineno" id="54">    54  </span>
<span class="lineno" id="55">    55  </span>	<span class="comment doc">/**
<span class="lineno" id="56">    56  </span>	 * remove tabs
<span class="lineno" id="57">    57  </span>	 * @param str (String)
<span class="lineno" id="58">    58  </span>	 * @return String
<span class="lineno" id="59">    59  </span>	 */</span>
<span class="lineno" id="60">    60  </span>	<span class="key">public</span> <span class="key">static</span> <span class="key">function</span> removeTabs(str:String):String {
<span class="lineno" id="61">    61  </span>		<span class="key">return</span> replace( str, <span class="str_const">"\t"</span>, <span class="str_const">""</span> );	
<span class="lineno" id="62">    62  </span>	}	
<span class="lineno" id="63">    63  </span>
<span class="lineno" id="64">    64  </span>	<span class="comment doc">/**
<span class="lineno" id="65">    65  </span>	 * remove spaces at end and beginning of the string only
<span class="lineno" id="66">    66  </span>	 * @param str (String)
<span class="lineno" id="67">    67  </span>	 * @return String
<span class="lineno" id="68">    68  </span>	 */</span>
<span class="lineno" id="69">    69  </span>	<span class="key">public</span> <span class="key">static</span> <span class="key">function</span> trim(str:String):String {
<span class="lineno" id="70">    70  </span>		<span class="key">var</span> index0:Number = <span class="num_const">0</span>;
<span class="lineno" id="71">    71  </span>		<span class="key">while</span> (str.charAt( index0 ) == <span class="str_const">" "</span>) {
<span class="lineno" id="72">    72  </span>			index0++;
<span class="lineno" id="73">    73  </span>		}
<span class="lineno" id="74">    74  </span>		<span class="key">var</span> index1:Number = str.length - <span class="num_const">1</span>;
<span class="lineno" id="75">    75  </span>		<span class="key">while</span> (str.charAt( index1 ) == <span class="str_const">" "</span>) {
<span class="lineno" id="76">    76  </span>			index1--;
<span class="lineno" id="77">    77  </span>		}
<span class="lineno" id="78">    78  </span>		<span class="key">return</span> str.substring( index0, index1 + <span class="num_const">1</span> );
<span class="lineno" id="79">    79  </span>	}
<span class="lineno" id="80">    80  </span>
<span class="lineno" id="81">    81  </span>	<span class="comment doc">/**
<span class="lineno" id="82">    82  </span>	 * remove spaces  tabs, line feeds, carrige returns from string
<span class="lineno" id="83">    83  </span>	 * @param str (String)
<span class="lineno" id="84">    84  </span>	 * @return String
<span class="lineno" id="85">    85  </span>	 */</span>
<span class="lineno" id="86">    86  </span>	<span class="key">public</span> <span class="key">static</span> <span class="key">function</span> xtrim(str:String):String {
<span class="lineno" id="87">    87  </span>		<span class="key">var</span> o:String = <span class="key">new</span> String( );
<span class="lineno" id="88">    88  </span>		<span class="key">var</span> TAB:Number = <span class="num_const">9</span>;
<span class="lineno" id="89">    89  </span>		<span class="key">var</span> LINEFEED:Number = <span class="num_const">10</span>;
<span class="lineno" id="90">    90  </span>		<span class="key">var</span> CARRIAGE:Number = <span class="num_const">13</span>;
<span class="lineno" id="91">    91  </span>		<span class="key">var</span> SPACE:Number = <span class="num_const">32</span>;
<span class="lineno" id="92">    92  </span>		<span class="key">for</span> (<span class="key">var</span> i:Number = <span class="num_const">0</span>; i &lt; str.length ; i++) {
<span class="lineno" id="93">    93  </span>			<span class="key">if</span> (str.charCodeAt( i ) != SPACE &amp;&amp; str.charCodeAt( i ) != CARRIAGE &amp;&amp; str.charCodeAt( i ) != LINEFEED &amp;&amp; str.charCodeAt( i ) != TAB) {
<span class="lineno" id="94">    94  </span>				o += str.charAt( i );
<span class="lineno" id="95">    95  </span>			}
<span class="lineno" id="96">    96  </span>		}
<span class="lineno" id="97">    97  </span>		<span class="key">return</span> o;
<span class="lineno" id="98">    98  </span>	}
<span class="lineno" id="99">    99  </span>
<span class="lineno" id="100">   100  </span>	<span class="comment doc">/**
<span class="lineno" id="101">   101  </span>	 * trim spaces and camel notate string
<span class="lineno" id="102">   102  </span>	 * @param str (String)
<span class="lineno" id="103">   103  </span>	 * @return String
<span class="lineno" id="104">   104  </span>	 */</span>
<span class="lineno" id="105">   105  </span>	<span class="key">public</span> <span class="key">static</span> <span class="key">function</span> trimCamel(str:String):String {
<span class="lineno" id="106">   106  </span>		<span class="key">var</span> o:String = <span class="key">new</span> String( );
<span class="lineno" id="107">   107  </span>		<span class="key">for</span> (<span class="key">var</span> i:Number = <span class="num_const">0</span>; i &lt; str.length ; i++) {
<span class="lineno" id="108">   108  </span>			<span class="key">if</span> (str.charAt( i ) != <span class="str_const">" "</span>) {
<span class="lineno" id="109">   109  </span>				<span class="key">if</span> (justPassedSpace) {
<span class="lineno" id="110">   110  </span>					o += str.charAt( i ).toUpperCase( );
<span class="lineno" id="111">   111  </span>					justPassedSpace = <span class="key">false</span>;
<span class="lineno" id="112">   112  </span>				} <span class="key">else</span> {
<span class="lineno" id="113">   113  </span>					o += str.charAt( i ).toLowerCase( );
<span class="lineno" id="114">   114  </span>				}
<span class="lineno" id="115">   115  </span>			} <span class="key">else</span> {
<span class="lineno" id="116">   116  </span>				<span class="key">var</span> justPassedSpace:Boolean = <span class="key">true</span>;
<span class="lineno" id="117">   117  </span>			}
<span class="lineno" id="118">   118  </span>		}
<span class="lineno" id="119">   119  </span>		<span class="key">return</span> o;
<span class="lineno" id="120">   120  </span>	}
<span class="lineno" id="121">   121  </span>
<span class="lineno" id="122">   122  </span>	<span class="comment doc">/**
<span class="lineno" id="123">   123  </span>	 * format a number with commas - ie. 10000 -&gt; 10,000
<span class="lineno" id="124">   124  </span>	 * @param inNum (Object) String or Number
<span class="lineno" id="125">   125  </span>	 * @return String
<span class="lineno" id="126">   126  </span>	 */</span>
<span class="lineno" id="127">   127  </span>	<span class="key">public</span> <span class="key">static</span> <span class="key">function</span> commaFormatNumber(inNum:Object):String {
<span class="lineno" id="128">   128  </span>		<span class="key">var</span> tmp:String = String( inNum );
<span class="lineno" id="129">   129  </span>		<span class="comment">//step through backwards and insert commas</span>
<span class="lineno" id="130">   130  </span>		<span class="key">var</span> outString:String = <span class="str_const">""</span>;
<span class="lineno" id="131">   131  </span>		<span class="key">var</span> l:Number = tmp.length;
<span class="lineno" id="132">   132  </span>		<span class="key">for</span> (<span class="key">var</span> i:Number = <span class="num_const">0</span>; i &lt; l ; i++) {
<span class="lineno" id="133">   133  </span>			<span class="key">if</span> (i % <span class="num_const">3</span> == <span class="num_const">0</span> &amp;&amp; i &gt; <span class="num_const">0</span>) {
<span class="lineno" id="134">   134  </span>				<span class="comment">//insert commas</span>
<span class="lineno" id="135">   135  </span>				outString = <span class="str_const">","</span> + outString;
<span class="lineno" id="136">   136  </span>			}
<span class="lineno" id="137">   137  </span>			outString = tmp.substr( l - (i + <span class="num_const">1</span>), <span class="num_const">1</span> ) + outString;
<span class="lineno" id="138">   138  </span>		}
<span class="lineno" id="139">   139  </span>		<span class="key">return</span> outString;		
<span class="lineno" id="140">   140  </span>	}
<span class="lineno" id="141">   141  </span>
<span class="lineno" id="142">   142  </span>	<span class="comment doc">/**
<span class="lineno" id="143">   143  </span>	 * Capitalize the first character in the string.
<span class="lineno" id="144">   144  </span>	 * @param str (String)
<span class="lineno" id="145">   145  </span>	 * @return String
<span class="lineno" id="146">   146  </span>	 */</span>
<span class="lineno" id="147">   147  </span>	 
<span class="lineno" id="148">   148  </span>	<span class="key">public</span> <span class="key">static</span> <span class="key">function</span> firstToUpper(str:String):String {
<span class="lineno" id="149">   149  </span>		<span class="key">return</span> str.charAt( <span class="num_const">0</span> ).toUpperCase( ) + str.substr( <span class="num_const">1</span> );
<span class="lineno" id="150">   150  </span>	}	
<span class="lineno" id="151">   151  </span>
<span class="lineno" id="152">   152  </span>	<span class="comment doc">/**
<span class="lineno" id="153">   153  </span>	 * encode html
<span class="lineno" id="154">   154  </span>	 * @param str (String)
<span class="lineno" id="155">   155  </span>	 * @return String
<span class="lineno" id="156">   156  </span>	 */</span>
<span class="lineno" id="157">   157  </span>	<span class="key">public</span> <span class="key">static</span> <span class="key">function</span> htmlEncode(str:String):String {
<span class="lineno" id="158">   158  </span>		<span class="key">var</span> s:String = str, a:Object = <span class="key">new</span> String( );
<span class="lineno" id="159">   159  </span>		a = s.split( <span class="str_const">"&amp;"</span> ), 
<span class="lineno" id="160">   160  </span>		s = a.join( <span class="str_const">"&amp;amp;"</span> );
<span class="lineno" id="161">   161  </span>		a = s.split( <span class="str_const">" "</span> ), 
<span class="lineno" id="162">   162  </span>		s = a.join( <span class="str_const">"&amp;nbsp;"</span> );
<span class="lineno" id="163">   163  </span>		a = s.split( <span class="str_const">"&lt;"</span> ), 
<span class="lineno" id="164">   164  </span>		s = a.join( <span class="str_const">"&amp;lt;"</span> );
<span class="lineno" id="165">   165  </span>		a = s.split( <span class="str_const">"&gt;"</span> ), 
<span class="lineno" id="166">   166  </span>		s = a.join( <span class="str_const">"&amp;gt;"</span> );
<span class="lineno" id="167">   167  </span>		a = s.split( <span class="str_const">"\""</span> ), 
<span class="lineno" id="168">   168  </span>		s = a.join( <span class="str_const">"&amp;quot;"</span> );
<span class="lineno" id="169">   169  </span>		<span class="key">return</span> s;
<span class="lineno" id="170">   170  </span>	}
<span class="lineno" id="171">   171  </span>
<span class="lineno" id="172">   172  </span>	<span class="comment doc">/**
<span class="lineno" id="173">   173  </span>	 * decode html
<span class="lineno" id="174">   174  </span>	 * @param t (String)
<span class="lineno" id="175">   175  </span>	 * @return String
<span class="lineno" id="176">   176  </span>	 */</span>
<span class="lineno" id="177">   177  </span>	<span class="key">public</span> <span class="key">static</span> <span class="key">function</span> htmlDecode(t:String):String {
<span class="lineno" id="178">   178  </span>		t = t.split( <span class="str_const">"&amp;reg;"</span> ).join( <span class="str_const">"¨"</span> );
<span class="lineno" id="179">   179  </span>		t = t.split( <span class="str_const">"&amp;copy;"</span> ).join( <span class="str_const">"©"</span> );
<span class="lineno" id="180">   180  </span>		t = t.split( <span class="str_const">"&amp;rsquo;"</span> ).join( <span class="str_const">"'"</span> );
<span class="lineno" id="181">   181  </span>		t = t.split( <span class="str_const">"&amp;ldquo;"</span> ).join( <span class="str_const">"\""</span> );
<span class="lineno" id="182">   182  </span>		t = t.split( <span class="str_const">"&amp;rdquo;"</span> ).join( <span class="str_const">"\""</span> );
<span class="lineno" id="183">   183  </span>		t = t.split( <span class="str_const">"&amp;hellip;"</span> ).join( <span class="str_const">"..."</span> );
<span class="lineno" id="184">   184  </span>		t = t.split( <span class="str_const">"&amp;middot;"</span> ).join( <span class="str_const">"*"</span> );
<span class="lineno" id="185">   185  </span>		t = t.split( <span class="str_const">"&amp;ndash;"</span> ).join( <span class="str_const">"-"</span> );
<span class="lineno" id="186">   186  </span>		t = t.split( <span class="str_const">"&amp;trade;"</span> ).join( <span class="str_const">"(TM)"</span> );
<span class="lineno" id="187">   187  </span>		t = t.split( <span class="str_const">"&amp;egrave;"</span> ).join( );
<span class="lineno" id="188">   188  </span>		t = t.split( <span class="str_const">"&amp;eacute;"</span> ).join( <span class="str_const">"Ž."</span> );
<span class="lineno" id="189">   189  </span>		t = t.split( <span class="str_const">"&amp;bull;"</span> ).join( <span class="str_const">"-"</span> );
<span class="lineno" id="190">   190  </span>		t = t.split( <span class="str_const">"&amp;amp;"</span> ).join( <span class="str_const">"&amp;"</span> );
<span class="lineno" id="191">   191  </span>		<span class="key">return</span> t;
<span class="lineno" id="192">   192  </span>	}
<span class="lineno" id="193">   193  </span>
<span class="lineno" id="194">   194  </span>	<span class="comment doc">/**
<span class="lineno" id="195">   195  </span>	 * strip the zero off floated numbers
<span class="lineno" id="196">   196  </span>	 * @param n (Number)
<span class="lineno" id="197">   197  </span>	 * @return String
<span class="lineno" id="198">   198  </span>	 */</span>	
<span class="lineno" id="199">   199  </span>	<span class="key">public</span> <span class="key">static</span> <span class="key">function</span> stripZeroOnFloat(n:Number):String {
<span class="lineno" id="200">   200  </span>		<span class="key">var</span> str:String = <span class="str_const">""</span>;
<span class="lineno" id="201">   201  </span>		<span class="key">var</span> a:Array = String( n ).split( <span class="str_const">"."</span> );
<span class="lineno" id="202">   202  </span>		<span class="key">if</span> (a.length &gt; <span class="num_const">1</span>) {
<span class="lineno" id="203">   203  </span>			str = (a[<span class="num_const">0</span>] == <span class="str_const">"0"</span>) ? <span class="str_const">"."</span> + a[<span class="num_const">1</span>] : String( n );
<span class="lineno" id="204">   204  </span>		} <span class="key">else</span> {
<span class="lineno" id="205">   205  </span>			str = String( n );
<span class="lineno" id="206">   206  </span>		}
<span class="lineno" id="207">   207  </span>		<span class="key">return</span> str;
<span class="lineno" id="208">   208  </span>	}
<span class="lineno" id="209">   209  </span>
<span class="lineno" id="210">   210  </span>	<span class="comment doc">/**
<span class="lineno" id="211">   211  </span>	 * add zero in front of floated number
<span class="lineno" id="212">   212  </span>	 * @param n (Number)
<span class="lineno" id="213">   213  </span>	 * @return String
<span class="lineno" id="214">   214  </span>	 */</span>
<span class="lineno" id="215">   215  </span>	<span class="key">public</span> <span class="key">static</span> <span class="key">function</span> padZeroOnFloat( n:Number ):String {
<span class="lineno" id="216">   216  </span>		<span class="key">return</span> ( n &gt; <span class="num_const">1</span> || n &lt; <span class="num_const">0</span> ) ? String( n ) : ( <span class="str_const">"0."</span> + String( n ).split( <span class="str_const">"."</span> )[<span class="num_const">1</span>] );	
<span class="lineno" id="217">   217  </span>	}
<span class="lineno" id="218">   218  </span>
<span class="lineno" id="219">   219  </span>	<span class="comment doc">/**
<span class="lineno" id="220">   220  </span>	 * Remove scientific notation from very small floats when casting to String.
<span class="lineno" id="221">   221  </span>	 * @param n (Number)
<span class="lineno" id="222">   222  </span>	 * @return String
<span class="lineno" id="223">   223  </span>	 * {@code Usage: 
<span class="lineno" id="224">   224  </span>	 * 	trace( String(0.0000001) ); // returns 1e-7
<span class="lineno" id="225">   225  </span>	 * 	trace( floatToString(0.0000001) ); // returns .00000001
<span class="lineno" id="226">   226  </span>	 * }
<span class="lineno" id="227">   227  </span>	 */</span>
<span class="lineno" id="228">   228  </span>	<span class="key">public</span> <span class="key">static</span> <span class="key">function</span> floatToString(n:Number):String {
<span class="lineno" id="229">   229  </span>		<span class="key">var</span> s:String = String( n );
<span class="lineno" id="230">   230  </span>		<span class="key">return</span> (n &lt; <span class="num_const">1</span> &amp;&amp; (s.indexOf( <span class="str_const">"."</span> ) &lt;= -<span class="num_const">1</span> || s.indexOf( <span class="str_const">"e"</span> ) &lt;= -<span class="num_const">1</span>)) ? <span class="str_const">"0."</span> + String( n + <span class="num_const">1</span> ).split( <span class="str_const">"."</span> )[<span class="num_const">1</span>] : s;
<span class="lineno" id="231">   231  </span>	}
<span class="lineno" id="232">   232  </span>
<span class="lineno" id="233">   233  </span>	<span class="comment doc">/**
<span class="lineno" id="234">   234  </span>	 * strip the zero off floated numbers and remove Scientific Notation
<span class="lineno" id="235">   235  </span>	 * @param n (Number)
<span class="lineno" id="236">   236  </span>	 * @return String
<span class="lineno" id="237">   237  </span>	 */</span>
<span class="lineno" id="238">   238  </span>	<span class="key">public</span> <span class="key">static</span> <span class="key">function</span> stripZeroAndRepairFloat(n:Number):String {
<span class="lineno" id="239">   239  </span>		<span class="key">var</span> str:String;
<span class="lineno" id="240">   240  </span>		<span class="key">var</span> tmp:String;
<span class="lineno" id="241">   241  </span>		<span class="key">var</span> isZeroFloat:Boolean;
<span class="lineno" id="242">   242  </span>		<span class="comment">// +=1 to prevent scientific notation.</span>
<span class="lineno" id="243">   243  </span>		<span class="key">if</span>(n &lt; <span class="num_const">1</span>) {
<span class="lineno" id="244">   244  </span>			tmp = String( (n + <span class="num_const">1</span>) );
<span class="lineno" id="245">   245  </span>			isZeroFloat = <span class="key">true</span>;
<span class="lineno" id="246">   246  </span>		} <span class="key">else</span> {
<span class="lineno" id="247">   247  </span>			tmp = String( n );
<span class="lineno" id="248">   248  </span>			isZeroFloat = <span class="key">false</span>;	
<span class="lineno" id="249">   249  </span>		}
<span class="lineno" id="250">   250  </span>		<span class="comment">// if we have a float strip the zero (or +=1) off!</span>
<span class="lineno" id="251">   251  </span>		<span class="key">var</span> a:Array = tmp.split( <span class="str_const">"."</span> );
<span class="lineno" id="252">   252  </span>		<span class="key">if</span> (a.length &gt; <span class="num_const">1</span>) {
<span class="lineno" id="253">   253  </span>			str = (a[<span class="num_const">0</span>] == <span class="str_const">"1"</span> &amp;&amp; isZeroFloat == <span class="key">true</span>) ? <span class="str_const">"."</span> + a[<span class="num_const">1</span>] : tmp;
<span class="lineno" id="254">   254  </span>		} <span class="key">else</span> {
<span class="lineno" id="255">   255  </span>			str = tmp;
<span class="lineno" id="256">   256  </span>		}
<span class="lineno" id="257">   257  </span>		<span class="key">return</span> str;
<span class="lineno" id="258">   258  </span>	}
<span class="lineno" id="259">   259  </span>
<span class="lineno" id="260">   260  </span>	<span class="comment doc">/**
<span class="lineno" id="261">   261  </span>	 * Generate a set of random characters
<span class="lineno" id="262">   262  </span>	 * @param amount (Number)
<span class="lineno" id="263">   263  </span>	 * @return String
<span class="lineno" id="264">   264  </span>	 */</span>
<span class="lineno" id="265">   265  </span>	<span class="key">public</span> <span class="key">static</span> <span class="key">function</span> randChar(amount:Number):String {
<span class="lineno" id="266">   266  </span>		<span class="key">var</span> str:String = <span class="str_const">""</span>;
<span class="lineno" id="267">   267  </span>		<span class="key">for</span>(<span class="key">var</span> i:Number = <span class="num_const">0</span>; i &lt; amount ; i++) str += chr( Math.round( Math.random( ) * (<span class="num_const">126</span> - <span class="num_const">33</span>) ) + <span class="num_const">33</span> );
<span class="lineno" id="268">   268  </span>		<span class="key">return</span> str;
<span class="lineno" id="269">   269  </span>	}
<span class="lineno" id="270">   270  </span>
<span class="lineno" id="271">   271  </span>	<span class="comment doc">/**
<span class="lineno" id="272">   272  </span>	 * Generate a set of random LowerCase characters
<span class="lineno" id="273">   273  </span>	 * @param amount (Number)
<span class="lineno" id="274">   274  </span>	 * @return String
<span class="lineno" id="275">   275  </span>	 */</span>	
<span class="lineno" id="276">   276  </span>	<span class="key">public</span> <span class="key">static</span> <span class="key">function</span> randLowerChar(amount:Number):String {
<span class="lineno" id="277">   277  </span>		<span class="key">var</span> str:String = <span class="str_const">""</span>;
<span class="lineno" id="278">   278  </span>		<span class="key">for</span>(<span class="key">var</span> i:Number = <span class="num_const">0</span>; i &lt; amount ; i++) str += chr( Math.round( Math.random( ) * (<span class="num_const">122</span> - <span class="num_const">97</span>) ) + <span class="num_const">97</span> );
<span class="lineno" id="279">   279  </span>		<span class="key">return</span> str;
<span class="lineno" id="280">   280  </span>	}
<span class="lineno" id="281">   281  </span>
<span class="lineno" id="282">   282  </span>	<span class="comment doc">/**
<span class="lineno" id="283">   283  </span>	 * Generate a set of random Number characters
<span class="lineno" id="284">   284  </span>	 * @param amount (Number)
<span class="lineno" id="285">   285  </span>	 * @return String
<span class="lineno" id="286">   286  </span>	 */</span>		
<span class="lineno" id="287">   287  </span>	<span class="key">public</span> <span class="key">static</span> <span class="key">function</span> randNum(amount:Number):String {
<span class="lineno" id="288">   288  </span>		<span class="key">var</span> str:String = <span class="str_const">""</span>;
<span class="lineno" id="289">   289  </span>		<span class="key">for</span>(<span class="key">var</span> i:Number = <span class="num_const">0</span>; i &lt; amount ; i++) str += chr( Math.round( Math.random( ) * (<span class="num_const">57</span> - <span class="num_const">48</span>) ) + <span class="num_const">48</span> );
<span class="lineno" id="290">   290  </span>		<span class="key">return</span> str;
<span class="lineno" id="291">   291  </span>	}
<span class="lineno" id="292">   292  </span>
<span class="lineno" id="293">   293  </span>	<span class="comment doc">/**
<span class="lineno" id="294">   294  </span>	 * Generate a set of random Special and Number characters
<span class="lineno" id="295">   295  </span>	 * @param amount (Number)
<span class="lineno" id="296">   296  </span>	 * @return String
<span class="lineno" id="297">   297  </span>	 */</span>		
<span class="lineno" id="298">   298  </span>	<span class="key">public</span> <span class="key">static</span> <span class="key">function</span> randSpecialChar(amount:Number):String {
<span class="lineno" id="299">   299  </span>		<span class="key">var</span> str:String = <span class="str_const">""</span>;
<span class="lineno" id="300">   300  </span>		<span class="key">for</span>(<span class="key">var</span> i:Number = <span class="num_const">0</span>; i &lt; amount ; i++) str += chr( Math.round( Math.random( ) * (<span class="num_const">64</span> - <span class="num_const">33</span>) ) + <span class="num_const">33</span> );
<span class="lineno" id="301">   301  </span>		<span class="key">return</span> str;
<span class="lineno" id="302">   302  </span>	}	
<span class="lineno" id="303">   303  </span>
<span class="lineno" id="304">   304  </span>	<span class="comment doc">/**
<span class="lineno" id="305">   305  </span>	 * strip html markup tags
<span class="lineno" id="306">   306  </span>	 * @param str (String)
<span class="lineno" id="307">   307  </span>	 * @return String
<span class="lineno" id="308">   308  </span>	 */</span>
<span class="lineno" id="309">   309  </span>	<span class="key">public</span> <span class="key">static</span> <span class="key">function</span> stripTags(str:String):String {
<span class="lineno" id="310">   310  </span>		<span class="key">var</span> s:Array = <span class="key">new</span> Array( );
<span class="lineno" id="311">   311  </span>		<span class="key">var</span> c:Array = <span class="key">new</span> Array( );
<span class="lineno" id="312">   312  </span>		<span class="key">for</span> (<span class="key">var</span> i:Number = <span class="num_const">0</span>; i &lt; str.length ; i++) {
<span class="lineno" id="313">   313  </span>			<span class="key">if</span> (str.charAt( i ) == <span class="str_const">"&lt;"</span>) {
<span class="lineno" id="314">   314  </span>				s.push( i );
<span class="lineno" id="315">   315  </span>			} <span class="key">else</span> <span class="key">if</span> (str.charAt( i ) == <span class="str_const">"&gt;"</span>) {
<span class="lineno" id="316">   316  </span>				c.push( i );
<span class="lineno" id="317">   317  </span>			}
<span class="lineno" id="318">   318  </span>		}
<span class="lineno" id="319">   319  </span>		<span class="key">var</span> o:String = str.substring( <span class="num_const">0</span>, s[<span class="num_const">0</span>] );
<span class="lineno" id="320">   320  </span>		<span class="key">for</span> (<span class="key">var</span> j:Number = <span class="num_const">0</span>; j &lt; c.length ; j++) {
<span class="lineno" id="321">   321  </span>			o += str.substring( c[j] + <span class="num_const">1</span>, s[j + <span class="num_const">1</span>] );
<span class="lineno" id="322">   322  </span>		}
<span class="lineno" id="323">   323  </span>		<span class="key">return</span> o;
<span class="lineno" id="324">   324  </span>	}
<span class="lineno" id="325">   325  </span>
<span class="lineno" id="326">   326  </span>	<span class="comment doc">/**
<span class="lineno" id="327">   327  </span>	 * detect html breaks
<span class="lineno" id="328">   328  </span>	 * @param str (String)
<span class="lineno" id="329">   329  </span>	 * @return Boolean
<span class="lineno" id="330">   330  </span>	 */</span>
<span class="lineno" id="331">   331  </span>	<span class="key">public</span> <span class="key">static</span> <span class="key">function</span> detectBr(str:String):Boolean {
<span class="lineno" id="332">   332  </span>		<span class="key">return</span> (str.split( <span class="str_const">"&lt;br"</span> ).length &gt; <span class="num_const">1</span>) ? <span class="key">true</span> : <span class="key">false</span>;
<span class="lineno" id="333">   333  </span>	}
<span class="lineno" id="334">   334  </span>
<span class="lineno" id="335">   335  </span>	<span class="comment doc">/**
<span class="lineno" id="336">   336  </span>	 * convert single quotes to double quotes
<span class="lineno" id="337">   337  </span>	 * @param str (String)
<span class="lineno" id="338">   338  </span>	 * @return String
<span class="lineno" id="339">   339  </span>	 */</span>
<span class="lineno" id="340">   340  </span>	<span class="key">public</span> <span class="key">static</span> <span class="key">function</span> toDoubleQuote(str:String):String {
<span class="lineno" id="341">   341  </span>		<span class="key">var</span> sq:String = <span class="str_const">"'"</span>;
<span class="lineno" id="342">   342  </span>		<span class="key">var</span> dq:String = String.fromCharCode( <span class="num_const">34</span> );
<span class="lineno" id="343">   343  </span>		<span class="key">return</span> str.split( sq ).join( dq );
<span class="lineno" id="344">   344  </span>	}
<span class="lineno" id="345">   345  </span>
<span class="lineno" id="346">   346  </span>	<span class="comment doc">/**
<span class="lineno" id="347">   347  </span>	 * convert double quotes to single quotes
<span class="lineno" id="348">   348  </span>	 * @param str (String)
<span class="lineno" id="349">   349  </span>	 * @return String
<span class="lineno" id="350">   350  </span>	 */</span>
<span class="lineno" id="351">   351  </span>	<span class="key">public</span> <span class="key">static</span> <span class="key">function</span> toSingleQuote(str:String):String {
<span class="lineno" id="352">   352  </span>		<span class="key">var</span> sq:String = <span class="str_const">"'"</span>;
<span class="lineno" id="353">   353  </span>		<span class="key">var</span> dq:String = String.fromCharCode( <span class="num_const">34</span> );
<span class="lineno" id="354">   354  </span>		<span class="key">return</span> str.split( dq ).join( sq );
<span class="lineno" id="355">   355  </span>	}
<span class="lineno" id="356">   356  </span>
<span class="lineno" id="357">   357  </span>	<span class="comment doc">/**
<span class="lineno" id="358">   358  </span>	 * Remove all formatting and return cleaned numbers from string.
<span class="lineno" id="359">   359  </span>	 * @param str (String)
<span class="lineno" id="360">   360  </span>	 * @return String
<span class="lineno" id="361">   361  </span>	 * {@code Usage: 
<span class="lineno" id="362">   362  </span>	 * 	StringUtils.toNumeric("123-123-1234"); // returns 1221231234 
<span class="lineno" id="363">   363  </span>	 * }
<span class="lineno" id="364">   364  </span>	 */</span>
<span class="lineno" id="365">   365  </span>	<span class="key">public</span> <span class="key">static</span> <span class="key">function</span> toNumeric(str:String):String {
<span class="lineno" id="366">   366  </span>		<span class="key">var</span> len:Number = str.length;
<span class="lineno" id="367">   367  </span>		<span class="key">var</span> result:String = <span class="str_const">""</span>;
<span class="lineno" id="368">   368  </span>		<span class="key">for</span> (<span class="key">var</span> i:Number = <span class="num_const">0</span>; i &lt; len ; i++) {
<span class="lineno" id="369">   369  </span>			<span class="key">var</span> code:Number = str.charCodeAt( i );
<span class="lineno" id="370">   370  </span>			<span class="key">if</span> (code &gt;= <span class="num_const">48</span> &amp;&amp; code &lt;= <span class="num_const">57</span>) {
<span class="lineno" id="371">   371  </span>				result += str.substr( i, <span class="num_const">1</span> );
<span class="lineno" id="372">   372  </span>			}
<span class="lineno" id="373">   373  </span>		}
<span class="lineno" id="374">   374  </span>		<span class="key">return</span> result;
<span class="lineno" id="375">   375  </span>	}
<span class="lineno" id="376">   376  </span>
<span class="lineno" id="377">   377  </span>	<span class="key">private</span> <span class="key">function</span> StringUtils() {
<span class="lineno" id="378">   378  </span>	}	
<span class="lineno" id="379">   379  </span>}</pre><ul class="main_nav" id="main_nav"><li><a href="../../../overview-summary.html" title="Overview of SASAPI" class="button">Overview</a></li><li><a href="package-summary.html" title="Overview of package com.sekati.utils" class="button">Package</a></li><li><a href="StringUtils.html" title="Detail of com.sekati.utils.StringUtils API" class="button">Class</a></li><li><span class="button nav_current">Source</span></li><li><a href="../../../index-files/index.html" title="Alpabetical index of types and members" class="button">Index</a></li></ul><div class="footer"><a href="http://www.badgers-in-foil.co.uk/projects/as2api/" title="ActionScript 2 API Documentation Generator">as2api</a></div></body></html>